/*
 *      Anim.h
 *      
 *      2009 Víctor Manuel Ochoa <kanito8a@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */


#ifndef ANIM_H
#define ANIM_H

#include "texture.h"
#include "time.h"
#include "entity.h"


#include <vector>
using namespace std;

const unsigned short MAX_FRAME_P0INTS=5;

// Animation Struct
typedef struct 
{
	std::vector<unsigned short> frames;
	unsigned int frame_time;
}Animation;

// Frame Point Struct
typedef struct 
{
	int x;
	int y;
}FramePoint;

// Animation Frame point Struct
typedef struct
{
	std::vector<FramePoint> framePoints;
}AnimationFramePoints;

class Anim:public Entity
{
	private:
		Texture *m_texture;
		Time m_time;
		Log    *m_pLog; 
		std::vector<unsigned short> m_animation;
		AnimationFramePoints m_frame_points[MAX_FRAME_P0INTS];
		
		unsigned short m_current_colum;
		unsigned short m_current_row;
		unsigned short m_colums_num;
		unsigned short m_rows_num;
		unsigned int m_frame_time;
		unsigned int m_last_time;
		
		unsigned short m_anim_size;
		unsigned short m_current_frame_num;
		
		float m_frame_colum_size;
		float m_frame_row_size;
		float m_frame_proportion;
		
		float m_frame_height;
		float m_frame_width;
		bool m_change_anim;
		
	public:
	
		Anim();
		virtual ~Anim();
		bool init(Texture *_texture,unsigned short _colums_num,unsigned short _rows_num);
		bool init(float _position[3],float _rotation,float _scale[3],Texture *_texture,unsigned short _colums_num,unsigned short _rows_num);
		void freeMemory();
		void draw();
		void update();		
		void setAnim(std::vector<unsigned short> _current_animation,unsigned int _frame_time);
		
		/*
		 * Inline get Functions
		 * */
		inline bool endOfAnim(){if (m_current_frame_num>=m_anim_size)return true;else return false;}
		inline FramePoint getFramePoint(unsigned short _point){return m_frame_points[_point].framePoints[m_animation[m_current_frame_num]];}
		
		
		/*
		 * Inline set/modification Functions
		 * */
		void setTexture(Texture *_texture){m_texture=_texture;}
		
		void setAnimationFramePoints(AnimationFramePoints m_frame_points[MAX_FRAME_P0INTS]);
		inline void restart(){m_current_frame_num=0;}
		
};

#endif /* ANIM_H */ 
